<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>取整操作</title>
</head>
<!-- https://www.zhihu.com/question/37846074 -->

<body>

</body>
<script>
  "use strict"; {
    let x = 1.23 | 0;  // 1
    console.log(x);

    let y = 5.345555;
    console.log((~~y));
  }; {
    // ~~也可以将undefind转为整数 0
    let i = undefined;
    console.log(~~i);
  }; {
    // 也可以将字符串转为数值并取整数
    let str = "1.2";
    console.log(~~str);
  };
</script>

</html>